<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://blogs">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />
	<xsl:include href="blocks.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/blogs.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/blogs.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />
			
			<!-- Header -->
			<div id="header">
				<xsl:call-template name="logo" />
				
				<!-- Menu -->
				<xsl:call-template name="menu" />
			</div>
			<!-- /Header -->
			
			<!-- Blocks -->
			<div id="blocks">
				<xsl:call-template name="default-blocks-top" />
				
				<div id="blocks_inner">
					<div class="block">
						<h4>&labelBlockCloud;</h4>
						<p>
							<xsl:apply-templates select="document('xmodule://blogs/getTagsCloud')/data/response" mode="block-tags-cloud" />
						</p>
					</div>
				</div>
			</div>
			<!-- // Blocks -->
			
			<!-- Content -->
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			<!-- // Content -->
			
			<!-- Address -->
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	
	<!-- RESPONSE -->
	<xsl:template match="response">
	
		<h1>&labelBlogsRating;</h1>
	
		<xsl:if test="count(object) = 0">
			<xsl:text>&labelThereAreNoBlogs;</xsl:text>
		</xsl:if>
	
		<xsl:if test="count(object) != 0">
			<table id="blogs_browse" cellspacing="10" cellpadding="0">
				<tr>
					<th />
					<th>&labelBlog;</th>
					<th class="c">&labelBlogMembers;</th>
					<th class="c">&labelPublications;</th>
					<th class="c">&labelRating;</th>
				</tr>
				<xsl:apply-templates select="object[@type='blog']" />
			</table>
		</xsl:if>
	
		<xsl:apply-templates select="pages" mode="pages-navigation">
			<xsl:with-param name="href">
				<xsl:value-of select="$baseURI" />
				<xsl:text>/blogs/top</xsl:text>
			</xsl:with-param>
		</xsl:apply-templates>	
	</xsl:template>
	
	<xsl:template match="object[@type='blog']">
		<xsl:param name="alias" select="property[@name='alias']/value" />
		<xsl:param name="avatar" select="property[@name='avatar']/value" />
		
		<tr>
			<td class="blog_avatar">
				<a href="{$baseURI}/blog/{$alias}">
					<xsl:if test="$avatar != ''">
						<img src="{$baseURI}/thumb_24_24{$avatar}" />
					</xsl:if>
					<xsl:if test="$avatar = ''">
						<img src="{$baseURI}/images/default-avatar-small.png" />
					</xsl:if>
				</a>
			</td>
			<td class="blog_desc">
				<h2>
					<a href="{$baseURI}/blog/{$alias}" class="header">
						<xsl:value-of select="property[@name='title']/value" />
					</a>
				</h2>
				<div class="blogs_administration">
					<xsl:text>&labelAdministration;: </xsl:text>
				
					<xsl:apply-templates select="document(concat('xmodule://blogs/getBlogAdmins/', @id))/data/response/object" mode="blog-admin" />					
					
				</div>
			</td>
			<td class="blog_readers">
				<div>
					<xsl:value-of select="property[@name='count_members']/value" />
				</div>
			</td>
			<td class="blog_posts">
				<div>
					<xsl:value-of select="property[@name='count_posts']/value" />
				</div>
			</td>
			<td class="blog_rating">
				<div>
					<xsl:value-of select="property[@name='rating']/value" />
				</div>
			</td>
		</tr>
	</xsl:template>
	
	<!-- BLOG ADMIN -->
	<xsl:template match="object[@type='blog_admin']" mode="blog-admin">
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<a href="{$baseURI}/user/{$userLogin}">
			<xsl:value-of select="property[@name='user_name']/value" />
		</a>
	</xsl:template>
	
</xsl:stylesheet>